//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	CamlQueryBuilderOrderBy.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common.Entities
{
	/// <summary>
	/// OrderBy group
	/// </summary>
	public class CamlQueryBuilderOrderBy<TExecutorType> : CamlQueryBuilderItemGroupGroupable<TExecutorType>, IQueryBuilderOrderBy<TExecutorType>
		where TExecutorType : class
	{
		public CamlQueryBuilderOrderBy()
			: base("OrderBy", false, true)
		{
		}

		/// <summary>
		/// Add sort by <paramref name="field"/> ascending
		/// </summary>
		public IQueryBuilderOrderBy<TExecutorType> Asc(string field)
		{
			AddItem(new CamlQueryBuilderOrderItem<TExecutorType>(field, "ASC"));

			return this;
		}

		/// <summary>
		/// Add sort by <paramref name="field"/> descending
		/// </summary>
		public IQueryBuilderOrderBy<TExecutorType> Desc(string field)
		{
			AddItem(new CamlQueryBuilderOrderItem<TExecutorType>(field, "DESC"));

			return this;
		}

		/// <summary>
		/// Add sort by <paramref name="field"/> with <paramref name="asc"/>
		/// </summary>
		public IQueryBuilderOrderBy<TExecutorType> Sort(string field, bool asc)
		{
			AddItem(new CamlQueryBuilderOrderItem<TExecutorType>(field, (asc ? "ASC" : "DESC")));

			return this;
		}
	}
}